package lanQiaoBei.数学知识.组合数学;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
题目链接   https://www.cnblogs.com/wKingYu/p/16269722.html
 */
public class P2 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=100010;
       static int c[]=new int[N],uc[]=new int[N],n,mod=(int)1e9+7;
       
       static long qmi(long a,long k){
    	      long res=1;
    	      while(k>0){
    	    	  if((k&1)==1)res=res*a%mod;
        	      k=k>>1;
        	      a=a*a%mod;
    	      }
    	     return res;
       }
       public static void main(String[] args) throws IOException {
		      n=Integer.parseInt(br.readLine());
		      c[0]=uc[0]=1;
		      for(int i=1;i<N;i++){
		    	  c[i]=(int)(1L*c[i-1]*i%mod);
		    	  uc[i]=(int)((uc[i-1]*qmi(i,mod-2)%mod));
		      }
		      while(n-->0){
		    	  String[]ss=br.readLine().split(" ");
		    	  int a=Integer.parseInt(ss[0]),b=Integer.parseInt(ss[1]);
		    	  System.out.println(1L*c[a]*uc[b]%mod*uc[a-b]%mod);
		      }
	}
}
